home *** CD-ROM | disk | FTP | other *** search
/ Total Web Page (Professional Suite) / Total Web Page 99.iso / CGI / DOWNLOAD.CGI-S=COUNTDOWN&C=TXT&F=COUNTDOWN.PL < prev    next >
Perl Script  |  1996-06-03  |  7KB  |  235 lines

  1. #!/usr/bin/perl
  2. ##############################################################################
  3. # Countdown                     Version 1.21                                 #
  4. # Copyright 1996 Matt Wright    mattw@worldwidemart.com                      #
  5. # Created 9/1/95                Last Modified 10/8/95                        #
  6. # Scripts Archive at:           http://www.worldwidemart.com/scripts/        #
  7. ##############################################################################
  8. # COPYRIGHT NOTICE                                                           #
  9. # Copyright 1996 Matthew M. Wright  All Rights Reserved.                     #
  10. #                                                                            #
  11. # Countdown may be used and modified free of charge by anyone so long as     #
  12. # this copyright notice and the comments above remain intact.  By using this #
  13. # code you agree to indemnify Matthew M. Wright from any liability that      #  
  14. # might arise from it's use.                                                 #  
  15. #                                                                            #
  16. # Selling the code for this program without prior written consent is         #
  17. # expressly forbidden.  In other words, please ask first before you try and  #
  18. # make money off of my program.                                              #
  19. #                                                                            #
  20. # Obtain permission before redistributing this software over the Internet or #
  21. # in any other medium.    In all cases copyright and header must remain intact.#
  22. ##############################################################################
  23. # Define Variables
  24.  
  25. # @from_date = (yyyy,mm,dd,hh,mm,ss);
  26. # Which means: (year,month,day,hour,minute,second)
  27. @from_date = (2000,1,1,0,0,0);
  28.  
  29. # Done
  30. ##############################################################################
  31.  
  32. $ENV{'QUERY_STRING'} =~ s/%2C/,/g;
  33. $ENV{'QUERY_STRING'} =~ s/=//g;
  34.  
  35. if ($ENV{'QUERY_STRING'}) {
  36.    @from_date = split(/,/, $ENV{'QUERY_STRING'});
  37. }
  38.  
  39. # Define when various things occur, different dates, etc...
  40. &define_dates;
  41.  
  42. # Calculate the Differences in the two dates
  43. &calc_dates;
  44.  
  45. # Make Sure we don't get negative times.. That's not cool...
  46. &no_negative;
  47.  
  48. # Top of HTML Page Information
  49. &html_header;
  50.  
  51. # We don't want it to say 1 Years, now, do we?  Of course not!
  52. &proper_english;
  53.  
  54. # End of HTML Page Information
  55. &html_trailer;
  56.  
  57. #####################################
  58. # Subroutines
  59.  
  60. sub define_dates {
  61.    ($f_year,$f_month,$f_day,$f_hour,$f_minute,$f_second) = @from_date;
  62.  
  63.    ($second,$minute,$hour,$day,$month,$year,$wday,$yday,$isdst) = localtime(time);
  64.  
  65.    $year ="19$year";
  66.  
  67.    &leap_year_check;
  68.  
  69.    @months = ("XX","January","February","March","April","May","June","July",
  70.               "August","September","October","November","December");
  71.  
  72.    @days = ("XX","1st","2nd","3rd","4th","5th","6th","7th","8th","9th","10th",
  73.             "11th","12th","13th","14th","15th","16th","17th","18th","19th",
  74.             "20th","21st","22nd","23rd","24th","25th","26th","27th","28th",
  75.             "29th","30th","31st");
  76.  
  77.    @days_in_month = (31,$feb_days,31,30,31,30,31,31,30,31,30,31);
  78.  
  79.    $date_term = "$months[$f_month] $days[$f_day]";
  80.  
  81.    unless ($f_year eq 'XX') {
  82.       $date_term = "$date_term, $f_year";
  83.    }
  84.    unless ($f_hour eq 'XX') {
  85.       $date_term = "$date_term $f_hour";
  86.    }
  87.    unless ($f_minute eq 'XX') {
  88.       if ($f_minute < 10) {
  89.          $date_term = "$date_term:0$f_minute";
  90.       }
  91.       else {
  92.          $date_term = "$date_term:$f_minute";
  93.       }
  94.    }
  95.    unless ($f_second eq 'XX') {
  96.       if ($f_second < 10) {
  97.          $date_term = "$date_term:0$f_second";
  98.       }
  99.       else {
  100.          $date_term = "$date_term:$f_second";
  101.       }
  102.    }
  103.  
  104.    $current_date = "$months[($month + 1)] $days[$day], $year $hour";
  105.    if ($minute < 10) {
  106.       $current_date = "$current_date:0$minute";
  107.    }
  108.    else {
  109.       $current_date = "$current_date:$minute";
  110.    }
  111.    if ($second < 10) {
  112.       $current_date = "$current_date:0$second";
  113.    }
  114.    else {
  115.       $current_date = "$current_date:$second";
  116.    }
  117.  
  118. }
  119.  
  120. sub leap_year_check {
  121.    $yeardiv = ($year / 4);
  122.    $yearint = int($yeardiv);
  123.    $yeardiv1 = ($year / 100);
  124.    $yearint1 = int($yeardiv1);
  125.  
  126.    if ($yeardiv eq $yearint && $yeardiv1 ne $yearint1) {
  127.       $feb_days = "28";
  128.    }
  129.    else {
  130.       $feb_days = "29";
  131.    }
  132. }
  133.  
  134. sub calc_dates {
  135.    $real_year = ($f_year - $year);
  136.    $real_month = (($f_month - 1) - $month);
  137.    $real_day = ($f_day - $day);
  138.    $real_hour = ($f_hour - $hour);
  139.    $real_minute = ($f_minute - $minute);
  140.    $real_second = ($f_second - $second);
  141. }
  142.  
  143. sub no_negative {
  144.    if ($real_second < 0) {
  145.       $real_second = ($real_second + 60);
  146.       $real_minute--;
  147.    }
  148.  
  149.    if ($real_minute < 0) {
  150.       $real_minute = ($real_minute + 60);
  151.       $real_hour--;
  152.    }
  153.  
  154.    if ($real_hour < 0) {
  155.       $real_hour = ($real_hour + 24);
  156.       $real_day--;
  157.    }
  158.  
  159.    if ($real_day < 0) {
  160.      $real_day = ($real_day + @days_in_month[$month]);
  161.       $real_month--;
  162.    }
  163.  
  164.    if ($real_month < 0) {
  165.       $real_month = ($real_month + 12);
  166.       $real_year--;
  167.    }
  168. }
  169.  
  170. sub proper_english {
  171.    unless ($f_year eq 'XX') {
  172.       if ($real_year eq '1') {
  173.          print "$real_year Year<br>\n";
  174.       } else {
  175.          print "$real_year Years<br>\n";
  176.       }
  177.    }
  178.  
  179.    unless ($f_month eq 'XX') {
  180.       if ($real_month eq '1') {
  181.          print "$real_month Month<br>\n";
  182.       } else {
  183.          print "$real_month Months<br>\n";
  184.       }
  185.    }
  186.  
  187.    unless ($f_day eq 'XX') {
  188.       if ($real_day eq '1') {
  189.          print "$real_day Day<br>\n";
  190.       } else {
  191.          print "$real_day Days<br>\n";
  192.       }
  193.    }
  194.  
  195.    unless ($f_hour eq 'XX') {
  196.       if ($real_hour eq '1') {
  197.          print "$real_hour Hour<br>\n";
  198.       } else {
  199.          print "$real_hour Hours<br>\n";
  200.       }
  201.    }
  202.  
  203.    unless ($f_minute eq 'XX') {
  204.       if ($real_minute eq '1') {
  205.          print "$real_minute Minute<br>\n";
  206.       } else {
  207.          print "$real_minute Minutes<br>\n";
  208.       }
  209.    }
  210.  
  211.    unless ($f_second eq 'XX') {
  212.       if ($real_second eq '1') {
  213.          print "$real_second Second<br>\n";
  214.       } else {
  215.          print "$real_second Seconds<br>\n";
  216.       }
  217.    }
  218.  
  219.  
  220. }
  221.  
  222. sub html_header {
  223.    print "Content-type: text/html\n\n";
  224.    print "<html><head><title>Countdown to: $date_term</title></head>\n";
  225.    print "<body><center><h1>Countdown to: $date_term</h1>\n";
  226.    print "<hr>\n";
  227. }
  228.  
  229. sub html_trailer {
  230.    print "<hr>\n";
  231.    print "It is currently $current_date\n";
  232.    print "</center>\n";
  233.    print "</body></html>\n";
  234. }
  235.